<template>
	<gui-page :refreshBgColor="['#112A87','##4969DE','#49A4F3','#ffffff']"
		:refreshColor="['#FFFFFF','#FFFFFF','#FFFFFF','#112A87']" ref="guipage" :refresh="true" @reload="reload">
		<view slot="gBody">
			<view class="top">
				<view class="search" @click="$u.to(`/pages/searchPage/index`)">
					<view class="left">
						<text class="gui-icons">&#xe604;</text>
						<view class="input">
							<input type="text" placeholder="请输入您要搜索的客户名/联系方式" placeholder-class="plStyle" />
						</view>
					</view>
					<view class="btn">
						搜索
					</view>
				</view>
				<view class="user_info">
					<view class="headImg">
						<gui-image :src="userInfo.avatar" :width="126" :height="126" borderRadius="50%" mode="aspectFill" v-if="userInfo.avatar"></gui-image>
						<image src="../../static/tx.png" style="width: 126rpx;height: 126rpx;" mode="aspectFill" v-else></image>
					</view>
					<view class="info f26">
						<text class="name" v-if="hasLogin">{{userInfo.realName || '--'}}</text>
						<text class="name" v-else>请先登录</text>
						<text>{{userInfo.organizeName || '--'}}</text>
					</view>
				</view>
				<view class="num_list">
					<view class="item f26" @click="$u.to(`/pages/announcement/index`)">
						<text>未读公告</text>
						<text class="num f28">{{readInfo.readCount || '0'}}</text>
					</view>
					<view class="item f26" @click="$u.to(`/pages/toDoList/toDoList`)">
						<text>待办事项</text>
						<text class="num f28">{{readInfo.backlogCount || '0'}}</text>
					</view>
					<view class="item f26" @click="$u.to(`/pages/client/client`, 'switchTab')">
						<text>我的客户</text>
						<text class="num f28">{{readInfo.clientCount || '0'}}</text>
					</view>
				</view>
			</view>
			<view class="content">
				<view class="waring f20" @tap="$u.to(`/pages/client/noContact`)" v-if="overClient == 1">
					<image src="../../static/image/danager.png" mode="widthFix" style="height: auto;"></image>
					<view class="con qoverDot">
						已有多个客户超过7天以上未联系
					</view>
					<text class="gui-icons">查看 &#xe601;</text>
				</view>
				<view class="title_box f30" style="margin-top: 40rpx;">
					我的工作
				</view>
				<view class="list_box">
					<view class="item" @click="$u.to(`/pages/toDoList/toDoList`)">
						<view class="left">
							<image src="../../static/index/work1.png" mode="widthFix" style="height: auto;"></image>
							<view class="info">
								<text class="name f30">待办事项</text>
								<text class="desc qoverDot2 f26">最近待办：{{readInfo.backlog.title || '无'}}</text>
							</view>
						</view>
						<view class="right f24">
							待办{{readInfo.backlogCount || 0}}条
						</view>
					</view>
					<view class="item" @click="$u.to(`/pages/announcement/index`)">
						<view class="left">
							<image src="../../static/index/work2.png" mode="widthFix" style="height: auto;"></image>
							<view class="info">
								<text class="name f32">企业公告</text>
								<text class="desc qoverDot2 f26">最新公告：{{readInfo.notice.title}}</text>
							</view>
						</view>
						<view class="right f24">
							未读{{readInfo.readCount}}条
						</view>
					</view>
				</view>
				<view class="title_box title_boxMargin f30">
					数据统计
				</view>
				<view class="radio_warp gui-flex gui-space-between">
					<view class="radio_item" @click="changeType(index)" v-for="(item,index) in timeArr" :key="index">
						<view class="item">
							<image src="@/static/image/un_checked.png" mode="aspectFit"
								v-show="currentIndex + '' !== index + ''"></image>
							<image src="@/static/image/checked.png" mode="aspectFit"
								v-show="currentIndex + '' === index + ''"></image>
						</view>
						<view class="text" :class="{'active' : currentIndex + '' === index + ''}">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="tj_warp gui-flex">
					<view class="left">
						<comEcharts :moduleParam="moduleParam2" v-if="moduleParam2.show" :optionData="option2" @changeOption="changeOption2()">
						</comEcharts>
					</view>
					<view class="right gui-flex gui-column gui-space-between">
						<view class="row_lengd gui-flex gui-align-items-center f24">
							<image src="@/static/image/star1.png" style="width: 23rpx;margin-right: 10rpx;"
								mode="widthFix"></image>
							完成转化客户数 {{this.finishiClient.percent}}%（{{this.finishiClient.value}}人）
						</view>
						<view class="row_lengd gui-flex gui-align-items-center f24">
							<image src="@/static/image/star2.png" style="width: 23rpx;margin-right: 10rpx;"
								mode="widthFix"></image>
							终止开发人数 {{this.endClient.percent}}%（{{this.endClient.value}}人）
						</view>
						<view class="row_lengd gui-flex gui-align-items-center f24">
							<image src="@/static/image/star3.png" style="width: 23rpx;margin-right: 10rpx;"
								mode="widthFix"></image>
							跟进中客户数 {{this.followClient.percent}}%（{{this.followClient.value}}人）
						</view>
					</view>
				</view>
				<view class="zw" style="height: 100rpx;">

				</view>
			</view>
			<gui-upload ref="guiUpload" uploadServerUrl="/api/common/version" :isHomePage="true"></gui-upload>
			<bai-daiban ref="baiDaiban" @btnClick="btnDaibanClick"></bai-daiban>
		</view>
	</gui-page>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	var colorList = [
		'#58D0FF',
		'#8479FF',
		'#FF6161',
		'#ef6567',
		'#f9c956',
		'#75bedc'
	];
	import comEcharts from '@/components/com-charts/com-charts.vue'
	export default {
		components: {
			comEcharts
		},
		computed: {
			...mapState(['userInfo', 'hasLogin', 'overClient', 'isReloadWin'])
		},
		data() {
			return {
				currentIndex: 0,
				endClient: {
					value: 0,
					percent: 0
				},
				finishiClient: {
					value: 0,
					percent: 0
				},
				followClient: {
					value: 0,
					percent: 0
				},
				moduleParam2: {
					id: "moId1",
					show: true,
					height: '267rpx'
				},
				option2: {
					tooltip: {
						trigger: 'item'
					},
					legend: {
						show: false
					},
					series: [{
						name: '',
						type: 'pie',
						radius: ['40%', '70%'],
						avoidLabelOverlap: false,
						label: {
							normal: {
								show: true,
								position: 'center',
								color: '#000',
								formatter: '{active|0}',
								rich: {
									active: {
										fontSize: uni.upx2px(24),
										color: '#030303'
									}
								}
							}
						},
						emphasis: {
							label: {
								show: true,
								fontSize: 40,
								fontWeight: 'bold'
							}
						},
						labelLine: {
							show: false
						},
						color: ['#58D0FF',
							'#8479FF',
							'#FF6161',
							'#ef6567',
							'#f9c956',
							'#75bedc'
						],
						data: [{
								value: 0,
								name: '终止开发人数'
							},
							{
								value: 0,
								name: '完成转换客户数'
							},
							{
								value: 0,
								name: '跟进中客户数'
							}
						]
					}, {
						type: 'pie',
						hoverAnimation: false, //鼠标移入变大
						center: ['50%', '50%'],
						radius: ['30%', '0%'],
						label: {
							normal: {
								show: false
							}
						},
						data: [{
							value: 9,
							name: '',
							itemStyle: {}
						}]
					}]
				},
				timeArr: [{
						value: 1,
						name: '一个月',
						check: true
					},
					{
						value: 2,
						name: '近三个月',
						check: false
					},
					{
						value: 3,
						name: '近一年',
						check: false
					},
					{
						value: 4,
						name: '全部',
						check: false
					}
				],
				readInfo: {
					readCount: 0,
					backlogCount: 0,
					clientCount: 0,
					notice: {},
					backlog: {
						title: ''
					}
				}
			}
		},
		onShow() {
			console.log("==================lailo");
			if (this.isReloadWin) {
				this.loadData();
			}
		},
		onLoad() {
			uni.$off('onload');
			uni.$on('onload', () => {
				if (this.hasLogin) {
					this.loadData();
					this.getBacklogNolist();
				}
			});
			this.loadData();
			this.getBacklogNolist();
			let CALLBACK = (result) => {
				if (result.isConnected) {
					this.loadData();
					this.getLocations();
					setTimeout(() => {
						this.$refs.guiUpload.showNow();
						uni.offNetworkStatusChange(CALLBACK);
					}, 100)

				}
			}
			uni.getNetworkType({
				success: (res) => {
					if (res.networkType == 'unknown' || res.networkType == 'none') {
						uni.onNetworkStatusChange(CALLBACK);
					} else {
						setTimeout(() => {
							this.$refs.guiUpload.showNow();
						}, 100)
					}
				}
			});
		},
		onUnload() {
			uni.$off('onload');
		},
		methods: {
			...mapActions(['updateReload']),
			btnDaibanClick() {
				this.$u.to(`/pages/toDoList/toDoList`);
			},
			getBacklogNolist() {
				this.$api.getBacklogNolist().then(res => {
					if (res.data.length > 0 && this.userInfo.noticeIs == 1) {
						this.$refs.baiDaiban.open();
					}
				})
			},
			loadData(isReload) {
				uni.showLoading({
					title: '请稍后...'
				})
				this.$api.noReadInfo({
					type: this.timeArr[this.currentIndex].value
				}).then(res => {
					uni.hideLoading();
					this.updateReload(false);
					this.readInfo = res.data;
					let data = [{
						value: this.readInfo.endClient,
						name: '终止开发人数'
					}, {
						value: this.readInfo.finishiClient,
						name: '完成转换客户数'
					}, {
						value: this.readInfo.followClient,
						name: '跟进中客户数'
					}]
					let total = this.readInfo.endClient;
					total = this.$u.operationAdd(total, this.readInfo.finishiClient);
					total = this.$u.operationAdd(total, this.readInfo.followClient);
					this.endClient = {
						value: this.readInfo.endClient,
						percent: this.$u.operationDiv(this.readInfo.endClient, total) ? this.$u.operationDiv(this.readInfo.endClient, total).toFixed(2) : 0
					};
					this.finishiClient = {
						value: this.readInfo.finishiClient,
						percent: this.$u.operationDiv(this.readInfo.finishiClient, total) ? this.$u.operationDiv(this.readInfo.finishiClient, total).toFixed(2) : 0
					};
					this.followClient = {
						value: this.readInfo.followClient,
						percent: this.$u.operationDiv(this.readInfo.followClient, total) ? this.$u.operationDiv(this.readInfo.followClient, total).toFixed(2) : 0
					};
					this.option2.series[0].data = data;
					this.option2.series[0].label.normal.formatter = '{active|' + total + '}';
					this.moduleParam2.show = false;
					this.$nextTick(() => {
						this.moduleParam2.show = true;
					})
					if(!this.readInfo.backlog) {
						this.readInfo.backlog = {
							title: ''
						}
					}
					if (isReload) {
						this.$refs.guipage.endReload();
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			reload: function() {
				this.loadData(1);
			},
			// 切换查询条件
			changeType(index) {
				this.currentIndex = index;
				this.loadData();
			}
		}
	}
</script>

<style lang="less">
	.top {
		background: url(../../static/index/indexBg.png) no-repeat;
		background-size: 100% 100%;
		padding: 104rpx 30rpx;
		color: #fff;

		.search {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #fff;
			border-radius: 50rpx;
			height: 64rpx;
			padding: 0 10rpx;

			.left {
				display: flex;
				align-items: center;
				flex: 1;

				.gui-icons {
					text-align: right;
					width: 53rpx;
					padding-right: 15rpx;
					border-right: 1px solid #999;
					color: #999;
				}

				.input {
					flex: 1;
					padding-left: 15rpx;

					input {
						width: 100%;
					}

					.plStyle {
						color: #999;
						font-size: 24rpx;
					}
				}
			}

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 96rpx;
				height: 56rpx;
				background: linear-gradient(225deg, #1890FF 0%, #0A60FF 100%);
				border-radius: 36rpx;
				font-size: 22rpx;
			}
		}

		.user_info {
			display: flex;
			margin-top: 40rpx;

			.headImg {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 138rpx;
				height: 138rpx;
				border-radius: 50%;
				background: #fff;
			}

			.info {
				display: flex;
				justify-content: center;
				flex-direction: column;
				margin-left: 24rpx;

				.name {
					margin-bottom: 11rpx;
					font-size: 32rpx;
				}
			}
		}

		.num_list {
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			.item {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;

				.num {
					margin-top: 10rpx;
				}
			}
		}

	}

	.content {
		padding: 0 30rpx;
		margin-top: -20rpx;

		.waring {
			position: relative;
			top: -46rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 82rpx;
			background: #fff;
			box-shadow: 0rpx 0rpx 30rpx 1rpx rgba(51, 51, 51, 0.1);
			border-radius: 10rpx;
			padding: 0 44rpx;

			image {
				width: 42rpx;
			}

			.con {
				flex: 1;
				margin: 0 24rpx 0 34rpx;
			}

			.gui-icons {
				color: #FB6547;
			}
		}

		.title_box {
			position: relative;
			padding-left: 20rpx;

			&:before {
				content: "";
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				width: 7rpx;
				height: 36rpx;
				background: #0E6EFF;
				border-radius: 2rpx;
			}
		}
	}

	.list_box {
		margin-top: 36rpx;

		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 37rpx 46rpx 37rpx 28rpx;
			background: #fff;
			box-shadow: 0rpx 0rpx 30rpx 1rpx rgba(51, 51, 51, 0.1);
			border-radius: 10rpx;
			margin-top: 16rpx;

			.left {
				display: flex;
				align-items: center;
				flex: 1;

				image {
					width: 96rpx;
				}

				.info {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					word-break: break-all;
					min-height: 96rpx;
					margin-left: 23rpx;
				}
			}

			.right {
				color: #0E6EFF;
				margin-left: 30rpx;
			}
		}
	}

	.title_boxMargin {
		margin: 34rpx 0;
	}

	.radio_warp {
		height: 60rpx;
		align-items: center;
	}

	.radio_item {
		display: flex;
		align-items: center;
		width: 25%;

		.item {
			display: flex;
			align-items: center;

			image {
				width: 25rpx;
				height: 25rpx;
			}
		}

		.text {
			margin-left: 20rpx;
			font-size: 26rpx;
			color: #999999;

			&.active {
				color: #0E6EFF;
			}
		}
	}

	.tj_warp {
		margin-top: ;
		justify-content: space-between;
		margin-top: 30rpx;

		.left {
			width: 267rpx;
			height: 267rpx;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			background: #FFFFFF;
			box-shadow: 0px 0 30px 1px rgba(51, 51, 51, 0.1);
		}

		.right {
			width: 406rpx;
			height: 267rpx;
			background: #FFFFFF;
			box-shadow: 0px 0 30rpx 1rpx rgba(51, 51, 51, 0.1);
			border-radius: 14rpx;
			padding: 50rpx 0 50rpx 30rpx;
		}
	}
</style>